// 测试类方法调用
class Person {
  static count = 0;
  name;
  age;

  constructor(name, age) {
    this.name = name;
    this.age = age;
    Person.count++;
  }

  // 实例方法
  sayHello() {
    return "Hello, I'm " + this.name;
  }

  // 实例方法访问属性
  getAge() {
    return this.age;
  }

  // 实例方法调用实例方法
  introduce() {
    return this.sayHello() + " and I'm " + this.getAge() + " years old.";
  }

  // 静态方法
  static create(name, age) {
    return new Person(name, age);
  }

  // 静态方法调用静态方法
  static createAndGreet(name, age) {
    const person = Person.create(name, age);
    return person.sayHello();
  }
}

// 创建实例并测试方法调用
console.log("测试实例化和实例方法:");
const p1 = new Person("Alice", 25);
console.log(p1.name);
console.log(p1.sayHello());
console.log(p1.getAge());
console.log(p1.introduce());

console.log("\n测试静态方法:");
const p2 = Person.create("Bob", 30);
console.log(p2.sayHello());
console.log(Person.createAndGreet("Charlie", 35));

// 测试继承和方法覆盖
console.log("\n测试继承:");
class Student extends Person {
  constructor(name, age, grade) {
    super(name, age);
    this.grade = grade;
  }

  // 覆盖父类方法
  sayHello() {
    return super.sayHello() + ", I'm a student";
  }

  // 新方法
  getGrade() {
    return this.grade;
  }

  // 组合使用父类和自己的方法
  introduce() {
    return super.sayHello() + ", grade " + this.getGrade() + ", age " + this.getAge();
  }
}

const s1 = new Student("David", 18, "12");
console.log(s1.sayHello());
console.log(s1.introduce()); 